<template>
  <div id="noteEditor">
    <Header :noteInfo="noteInfo"/>
    <main :style="`height:${this.$store.state.screenHeight - 61}px`">
      <div class="spacing"></div>
      <quillEditor/>
    </main>
  </div>
</template>

<script>
// 引入header2组件
import Header from "@/components/NoteEditor/headerCps.vue";
import quillEditor from "@/components/NoteEditor/quillEditor.vue";

export default {
  name: "NoteEditor",
  components: {
    Header,
    quillEditor
  },
  data(){
    return {
      noteInfo:{}
    }
  },
  mounted() {
    console.log("id:",this.$route.params.id);
    this.getNoteInfo(this.$route.params.id);
    // 设置监听窗口大小事件，当窗口大小改变时回调handleResize方法
    window.addEventListener("resize", this.handleResize);
    // 调用窗口回调事件
    this.handleResize();
  },
  methods: {
    // 窗口大小改变回调
    handleResize() {
      // 通过vuex修改窗口高度
      this.$store.commit("setScreenHeight", document.body.clientHeight);

      // console.log(this.$store.state.screenHeight);
    },
    // 获取当前笔记信息
    async getNoteInfo(noteId){
      const {data:res} =await this.$http.getNoteByNoteId(noteId);
      console.log(res.data.noteList);
      this.noteInfo = res.data.noteList;
      //通知富文本编辑器更新笔记信息
      this.$bus.$emit("resetNoteInfo",res.data.noteList);
    }

  },
};
</script>

<style lang="less" scoped>
#noteEditor {
  width: 100%;
  height: 100%;
  font-size: 16px;
  position: relative;
  main {
    width: 1024px;
    // height: 800px;
    background-color: white;
    position: relative;
    top: 60px;
    left: 50%;
    transform: translateX(-50%);
    .spacing {
      width: 100%;
      height: 10px;
      background-color: rgb(102, 170, 207);
    }
  }
}
@media (max-width: 1024px) {
  #noteEditor {
    main {
      width: 100%;
    }
  }
}
</style>